﻿using System;

class Program
{

    static void Main()
    {
        int[,] matrix =
        {
            {1,2,3,40,5},
            {1,2,3,40,5},
            {1,2,3,4,5},
            {1,2,3,4,5},
        };
        int bestSum = int.MinValue;
        int bestR=0;
        int bestC=0;
        for (int r = 0; r < matrix.GetLength(0)-2; r++)
        {
            for (int c = 0; c < matrix.GetLength(1)-2; c++)
            {
                int s = matrix[r, c] + matrix[r, c + 1] + matrix[r, c + 2] + matrix[r + 1, c] + matrix[r + 1, c + 1] + matrix[r + 1, c + 2] + matrix[r + 2, c] + matrix[r + 2, c + 1] + matrix[r + 2, c + 2];
                if (s > bestSum)
                {
                    bestR = r;
                    bestC = c;
                    bestSum = s;
                }
            }
        }
        Console.WriteLine(bestSum);
        Console.WriteLine("{0,5}{1,5}{2,5}", matrix[bestR, bestC], matrix[bestR, bestC + 1], matrix[bestR, bestC + 2]);
        Console.WriteLine("{0,5}{1,5}{2,5}", matrix[bestR+1, bestC], matrix[bestR+1, bestC + 1], matrix[bestR+1, bestC + 2]);
        Console.WriteLine("{0,5}{1,5}{2,5}", matrix[bestR+2, bestC], matrix[bestR+2, bestC + 1], matrix[bestR+2, bestC + 2]);
    }
}